<template>
  <div class="home-banner">
    <el-carousel height="500px">
      <el-carousel-item v-for="item in bannerData" :key="item.id">
        <img :src="item.imgUrl" alt="">
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script setup>
import { getBannerAPI } from '@/apis/home.js'
import { onMounted, ref } from 'vue'

let bannerData = ref([])

const getBanner = async () => {
  // 函数定义name（）{}和调用带有name（）。
  const res = await getBannerAPI()
  // ref使用是需要.value来赋值，不然会报错。
  bannerData.value = res.result
}
onMounted(() => {
  getBanner()
})
</script>

<style lang="scss" scoped>
.home-banner {
  width: 80%;
  height: 500px;
  margin-left: 18%;
  z-index: 98;

  img {
    width: 100%;
    height: 500px;
  }
}
.remBanner {
  margin: 0 auto;
  position: static;
}
</style>